﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace WindowsPhoneHostAgent
{
    public class TestRunStatusColumn : DataGridViewColumn
    {
        public TestRunStatusColumn()
            : base(new TestRunStatusCell())
        {
        }

        public override DataGridViewCell CellTemplate
        {
            get
            {
                return base.CellTemplate;
            }
            set
            {
                // Ensure that the cell used for the template is a CalendarCell.
                if (value != null &&
                    !value.GetType().IsAssignableFrom(typeof(TestRunStatusCell)))
                {
                    throw new InvalidCastException("Must be a TestRunStatusCell");
                }
                base.CellTemplate = value;
            }
        }
    }

    public class TestRunStatusCell : DataGridViewTextBoxCell
    {
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
            Point pt = cellBounds.Location;
            pt.Offset(2, 2);
            string statusIcon;
            string status;
            if (value == null)
                throw new Exception("State null Exception");
            switch (value as string)
            {
                case "1":
                    statusIcon = "running.png";
                    status = "In Process";
                    break;
                case "2":
                    statusIcon = "pass.png";
                    status = "Pass";
                    break;
                case "3":
                    statusIcon = "failed.png";
                    status = "Failed";
                    break;
                default:
                    statusIcon = "pending.png";
                    status = "Pending";
                    break;
            }
            graphics.DrawImage(Image.FromFile("Resources/" + statusIcon), pt);
            pt.Offset(16, 0);
            graphics.DrawString(status, cellStyle.Font, Brushes.Black, pt);
        }
    }

}
